package com.twu.biblioteca;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * Created by xndong on 10/6/14.
 */
public class MovieList {
    static ArrayList<Movie> movieList = new ArrayList<Movie>();

    public MovieList() {
        movieList.add(new Movie("movie name",2000,1,"director",false));
        movieList.add(new Movie("movie name",2000,0,"director",false));
    }

    public MovieList(Movie item){
        this.movieList.add(item);
    }

    public MovieList(ArrayList<Movie> items){
        this.movieList = items;
    }

    public static void Return(String input, Customer currentUser) {
        Movie movie = GetItem(input);
        movie.Return(currentUser.Identity);
        Update(movie);
    }

    public static void CheckOut(String input, Customer currentUser) {
        Movie movie = GetItem(input);
        movie.CheckOut(currentUser.Identity);
        Update(movie);
    }

    private static void Update(Movie movie) {
        movieList.remove(movie);
        movieList.add(movie);
    }

    private static Movie GetItem(String input){
        if(input.isEmpty()) return null;
        int index = Integer.parseInt(input) - 1;
        Iterator<Movie> it = movieList.iterator();
        while (it.hasNext()) {
            if( it.next().MovieId == index) return it.next();
        }
        return null;
    }


}
